import { ref, onMounted } from 'vue';
import { listTeacher} from '@/api/core/teacher';

// 定义教师选项的接口
interface TeacherOptionsType {
  id: number | string;
  name: string;
  // 其他字段根据实际情况添加
}

// 封装的公共方法
export function useTeacherList(): {
  teacherOptions: TeacherOptionsType[];
  fetchTeacherList: () => Promise<void>;
} {
  const teacherOptions = ref<TeacherOptionsType[]>([]);

  const fetchTeacherList = async (): Promise<void> => {
    try {
      const res = await listTeacher();
      teacherOptions.value = res.rows;
    } catch (error) {
      console.error('Failed to fetch teacher list:', error);
    }
  };

  onMounted(fetchTeacherList); // 可选：如果需要在组件挂载时自动加载数据

  return { teacherOptions, fetchTeacherList };
}

import { listSubject } from '@/api/core/subject';

// 定义学科选项的接口
interface SubjectOptionsType {
  id: number | string;
  subjectName: string;
  // 其他字段根据实际情况添加
}

// 封装的公共方法
export function useSubjectList(): {
  subjectOptions: SubjectOptionsType[];
  fetchSubjectList: () => Promise<void>;
} {
  const subjectOptions = ref<SubjectOptionsType[]>([]);

  const fetchSubjectList = async (): Promise<void> => {
    try {
      const res = await listSubject();
      subjectOptions.value = res.rows;
    } catch (error) {
      console.error('Failed to fetch subject list:', error);
    }
  };

  onMounted(fetchSubjectList); // 可选：如果需要在组件挂载时自动加载数据

  return { subjectOptions, fetchSubjectList };
}